package com.audaque.springboot.foshanupload.core.handler;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author zgb
 * @desc ...
 * @date 2021-06-15 14:28:51
 */
@Slf4j
public class RejectedExecutionHandlerImpl implements RejectedExecutionHandler {
    //自定义拒绝策略：重新put Runnable：将指定的元素插入此队列，必要时等待空间变为可用。即一直等待到有位置
    //变更点，注意，此处把线程池中的阻塞队列拿出来，重新put Runnable
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        try {
            executor.getQueue().put(r);
        } catch (InterruptedException e) {
            e.printStackTrace();
            log.error("异常栈:"+e);
        }
    }

}
